<?php

namespace App\HttpController;

use App\Service\FriendService;
use EasySwoole\HttpAnnotation\AnnotationTag\Api;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiDescription;
use EasySwoole\HttpAnnotation\AnnotationTag\ApiGroup;
use EasySwoole\HttpAnnotation\AnnotationTag\Method;
use EasySwoole\HttpAnnotation\AnnotationTag\Param;
use EasySwoole\Mysqli\Exception\Exception;
use Throwable;

/**
 * @ApiGroup(groupName="好友")
 */
class Friend extends StaffController
{
    /**
     * @ApiDescription(value="获取好友列表")
     * @Api(name="获取好友列表", path="/friend/getMyFriend", version="1.0.0")
     * @Method(allow={POST})
     * @Param(name="type", description="类型", defaultValue="0", from={JSON})
     * @return bool
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\ORM\Exception\Exception
     */
    public function getMyFriend($type): bool
    {
        $res = FriendService::getInstance()->getMyFriend($this->sid, $type);
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }

    /**
     * @ApiDescription(value="修改好友备注")
     * @Api(name="修改好友备注", path="/friend/changeMemo", version="1.0.0")
     * @Method(allow={POST})
     * @Param(name="fsid", description="好友sid", required="", from={JSON})
     * @Param(name="memo", description="备注", required="", from={JSON})
     * @return bool
     * @throws Exception
     * @throws Throwable
     * @throws \EasySwoole\ORM\Exception\Exception
     */
    public function changeMemo($fsid, $memo): bool
    {
        $res = FriendService::getInstance()->changeMemo($this->sid, $fsid, $memo);
        if (!$res['result']) {
            return $this->writeJsonError($res['msg']);
        }
        return $this->writeJsonSuccess($res['data'], $res['msg']);
    }
}